﻿using System.Text;

namespace MRMDS.Utils
{
    public class HtmlHelper
    {
        private StringBuilder builder;

        public HtmlHelper()
        {
            builder = new StringBuilder();
        }
        public void Clear()
        {
            builder.Clear();
        }
        public string GetResult()
        {
            return builder.ToString();
        }
        #region html Options
        public void Html(bool state)
        {
            builder.Append(state ? "<html>" : "</html>");
        }
        public void Body(bool state)
        {
            builder.Append(state ? "<body>" : "</body>");
        }
        public void Lable(string info)
        {
            builder.Append($"<lable>{info}</lable>");
        }
        public void Table(bool state)
        {
            builder.Append(state ? "<table border=\"1\">" : "</table>");
        }
        public void TR(bool state)
        {
            builder.Append(state ? "<tr>" : "</tr>");
        }
        public void TD<T>(T info)
        {
            builder.Append($"<td>{info}</td>");
        }
        public void SmartTR(string[] items)
        {
            TR(true);
            foreach (var item in items)
            {
                TD(item);
            }
            TR(false);
        }
        public void SmartTable(string[,] grid)
        {
            Table(true);
            for (int x = 0; x < grid.GetLength(0); x++)
            {
                TR(true);
                for (int y = 0; y < grid.GetLength(1); y++)
                {
                    TD(grid[x, y]);
                }
                TD(false);
            }
            Table(false);
        }
        #endregion

    }
}
